﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace Inovout.Data.Repository.Linq
{
    internal class FilterExpression
    {
        private IEnumerable<FilterCriteria> filterCriterions;
        public FilterItemExpression[] Filters { get; private set; }
        public string[] Values { get; private set; }
        internal FilterExpression(IEnumerable<FilterCriteria> filterCriterions)
        {
            this.filterCriterions = filterCriterions.Where(f => !string.IsNullOrEmpty(f.FilterValue))
                .OrderBy(f => f.FilterName).OrderBy(f=>f.FilterOperation);
            this.Filters = this.filterCriterions
                .Select((f, i) => { return new FilterItemExpression(i, f.FilterName, f.FilterOperation); })
                .ToArray();
            this.Values = this.filterCriterions.Select(f => f.FilterValue).ToArray();
        }

    }
}
